//
//  CellForTennis.m
//  MY Project For Sport
//
//  Created by dllo on 16/2/1.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "CellForTennis.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "ModelForTennis.h"
#import <DKNightVersion.h>
#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

#define WEIGHTT [UIScreen mainScreen].bounds.size.width / 375
#define HEIGHTT [UIScreen mainScreen].bounds.size.height / 667


@interface CellForTennis ()
@property (nonatomic, retain) UILabel *labelForOrder;
@property (nonatomic, retain) UIImageView *ImageForName;
@property (nonatomic, retain) UILabel *labelForName;
@property (nonatomic, retain) UILabel *labelForNation;
@property (nonatomic, retain) UILabel *labelForScore;
@property (nonatomic, retain) UILabel *labelForCount;


@end

@implementation CellForTennis
-(void)dealloc {
    [_labelForCount release];
    [_ImageForName release];
    [_labelForName release];
    [_labelForNation release];
    [_labelForOrder release];
    [_labelForScore release];
    [super dealloc];

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);

        [self createSubview];
        
    }

    return self;

}

- (void)createSubview {

    self.labelForCount = [[UILabel alloc] init];
    [self.contentView addSubview: self.labelForCount];
    [_labelForCount release];
    
    self.ImageForName = [[UIImageView alloc] init];
    [self.contentView addSubview:self.ImageForName];
    [_ImageForName release];
    
    self.labelForName = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForName];
    [_labelForName release];
    
    self.labelForNation = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForNation];
    [_labelForNation release];
    
    self.labelForOrder = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForOrder];
    [_labelForOrder release];
    
    self.labelForScore = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForScore];
    [_labelForScore release];

}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.labelForOrder.frame = CGRectMake(20 * WEIGHTT, WIDTH / 28, WIDTH / 15, WIDTH / 15);
    self.labelForOrder.layer.cornerRadius = WIDTH / 30;
    self.labelForOrder.layer.masksToBounds = YES;
   // self.labelForOrder.backgroundColor = [UIColor redColor];

    self.ImageForName.frame = CGRectMake(10 * WEIGHTT + WIDTH / 15 + WIDTH / 15 + WIDTH / 10, 5 * HEIGHTT, WIDTH / 11, WIDTH / 11);
    self.ImageForName.layer.cornerRadius = WIDTH / 22;
    self.ImageForName.layer.masksToBounds = YES;
   // self.ImageForName.backgroundColor = [UIColor redColor];

    self.labelForName.frame = CGRectMake(WIDTH / 15 + WIDTH / 15 + WIDTH / 10, WIDTH / 11 + 7 * HEIGHTT, WIDTH / 8 + 5 * WEIGHTT, WIDTH / 35) ;
  //  self.labelForName.backgroundColor = [UIColor redColor];
    
    
    self.labelForNation.frame = CGRectMake(30 * WEIGHTT + WIDTH / 15 + WIDTH / 5 + WIDTH / 13, WIDTH / 28, WIDTH / 5, WIDTH / 15);
   // self.labelForNation.backgroundColor = [UIColor grayColor];

    self.labelForScore.frame = CGRectMake(30 * WEIGHTT + WIDTH / 15 + WIDTH / 4 + WIDTH / 13 * 4, WIDTH / 28, WIDTH / 9, WIDTH / 15);
  //  self.labelForScore.backgroundColor = [UIColor greenColor];
    
    self.labelForCount.frame = CGRectMake(30 * WEIGHTT + WIDTH / 20 + WIDTH / 15 + WIDTH / 4 + WIDTH / 13 * 5, WIDTH / 28, WIDTH / 6, WIDTH / 15);
   // self.labelForCount.backgroundColor = [UIColor orangeColor];
    
}

- (void)passModelForTennis:(ModelForTennis *)model {

    self.labelForOrder.text = model.rank;
    self.labelForCount.textAlignment = NSTextAlignmentCenter;
    [self.ImageForName sd_setImageWithURL:[NSURL URLWithString:model.playerid1_logo]];
    self.labelForName.text = model.playername1;
    self.labelForName.font = [UIFont systemFontOfSize:10];
    self.labelForName.textAlignment = NSTextAlignmentCenter;
    self.labelForNation.text = model.nation1;
    self.labelForNation.textAlignment = NSTextAlignmentCenter;
    self.labelForScore.text = model.score;
    self.labelForScore.font = [UIFont systemFontOfSize:12];
    self.labelForCount.text = model.matchcount;
    self.labelForCount.textAlignment = NSTextAlignmentCenter;

}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
